package com.dc.bobaoge.project.v2.to.v3.business.core.method.message;

import com.dc.bobaoge.base.entity.message.core.po.MessageRecruit;
import com.dc.bobaoge.base.mapper.message.MessageRecruitMapper;
import com.dc.bobaoge.common.em.MessageTemplateEnum;
import com.dc.bobaoge.project.base.core.old.entity.OldCoreMessage;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.function.Consumer;

/**
 * MessageTemplate3ResolveMethod
 *
 * @author chenxueli
 * @date 2024-01-15 13:03:11
 */
@Component
public class MessageTemplate3ResolveMethod extends AbstractResolveMessageMethod<
        MessageRecruit,
        MessageRecruitMapper
        > {

    @Resource
    private MessageRecruitMapper messageRecruitMapper;

    /**
     * 新增的方法信息
     *
     * @param oldCoreMessage 旧消息信息
     * @param supplier       额外操作
     * @return 最终的数据
     */
    @Override
    protected MessageRecruit add(OldCoreMessage oldCoreMessage, Consumer<MessageRecruit> supplier) {
        var message = resolvePo(new MessageRecruit(), oldCoreMessage);
        supplier.accept(message);
        // 处理其他信息
        messageRecruitMapper.insert(message);
        return message;
    }

    /**
     * 更新的方法信息
     *
     * @param message        新消息信息
     * @param oldCoreMessage 旧消息信息
     * @param supplier       额外操作
     * @return 最终的数据
     */
    @Override
    protected MessageRecruit update(MessageRecruit message, OldCoreMessage oldCoreMessage, Consumer<MessageRecruit> supplier) {
        supplier.accept(message);
        // 处理其他信息
        messageRecruitMapper.updateById(message);
        return message;
    }

    /**
     * 获取消息的模板信息
     *
     * @return 消息的模板信息
     */
    @Override
    public MessageTemplateEnum getMessageTemplate() {
        return MessageTemplateEnum.RECRUIT;
    }

}
